import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Main from '../components/Main.vue'
import tRegister from '../components/tRegister.vue'
import Contact from '../components/Contact.vue'
import sRegister from '../components/sRegister.vue'
import newContainner from '../components/NewContainner.vue'
import Home from '../page/Home.vue'
import Apply from '../page/Apply.vue'
import MyShare from '../page/MyShare.vue'
import BookDisplay from '../page/BookDisplay.vue'

Vue.use(VueRouter)

const routes = [
  // {
  //   path: '/',
  //   name: 'main',
  //   component: Main,
  //   redirect: '/home',
  //   children: [
  //     // { path: '/home', name: 'home', component: Home },
  //     // { path: '/apply', name: 'apply', component: Apply },
  //     // { path: '/record', name: 'record', component: Record },
  //     // { path: '/share', name: 'share', component: Share }
  //   ]
  // },
  {
    path: '/',
    name: 'newContainner',
    component: newContainner,
    redirect: '/home',
    children: [
      { path: '/home', name: 'home', component: Home },
      { path: '/apply', name: 'apply', component: Apply },
      { path: '/myShare', name: 'myShare', component: MyShare },
      { path: '/bookDisplay', name: 'bookDisplay', component: BookDisplay }
    ]
  },
  {
    path: '/main',
    name: 'main',
    component: Main,
    redirect: () => {
      if (window.localStorage.getItem('token')) {
        const role = JSON.parse(window.localStorage.getItem('userInfo')).role
        if (role == 1) {
          return '/myApply'
        } else if (role == 2) {
          return '/mypublish'
        } else if (role == 3) {
          return '/schoolTab'
        } else {
          return '/main'
        }
      }
      return '/myApply'
    },
    children: [
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/tRegister',
    name: 'tRegister',
    component: tRegister
  },
  {
    path: '/sRegister',
    name: 'sRegister',
    component: sRegister
  },
  {
    path: '/contact',
    name: 'contact',
    component: Contact
  }

]

const router = new VueRouter({
  routes
})

export default router
